package com.fw.ui.bao;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.service.globalsetting.GlobalSettingService;
import com.fw.service.globalsetting.bean.GlobalSettingBean;
import com.fw.ui.service.ServiceExecutor;
import com.fw.ui.service.ServiceOrder;

@Component
@Scope(SCOPE_PROTOTYPE)
public class GlobalSettingBAO extends AbstractBAO implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Autowired
    private GlobalSettingService globalSettingService;

    public GlobalSettingBean getGlobalSetting() throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.globalSettingService);
	    serviceOrder.setMethodName("getGlobalSetting");
	    serviceOrder.setParameterTypes(new Class[] {});
	    serviceOrder.setParameterValues(new Object[] {});

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		GlobalSettingBean globalSettingBean = (GlobalSettingBean) serviceOrder.getReturnValue();
		return globalSettingBean;
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    public GlobalSettingBean setGlobalSetting(GlobalSettingBean globalSettingBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.globalSettingService);
	    serviceOrder.setMethodName("setGlobalSetting");
	    serviceOrder.setParameterTypes(new Class[] { GlobalSettingBean.class });
	    serviceOrder.setParameterValues(new Object[] { globalSettingBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		GlobalSettingBean bean = (GlobalSettingBean) serviceOrder.getReturnValue();
		return bean;
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

}
